package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@LagouController
@LagouRequestMapping("/demo")
//@Security(values = {"lisi"})
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     *
     * @param request
     * @param response
     * @param name
     * @return
     */
    @Security(values = {"lisi"})
    @LagouRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response, String name, String sex) throws IOException {
        String s = demoService.get(name);
        response.getWriter().write(s+"有权限访问此接口");
        return s;
    }

    /**
     * 删除
     * @param request
     * @param response
     * @param name
     * @param sex
     * @return
     * @throws IOException
     */
    @Security(values = {"zhangsan"})
    @LagouRequestMapping("/delete")
    public String delete(HttpServletRequest request, HttpServletResponse response, String name, String sex) throws IOException {
        String s = demoService.get(name);
        response.getWriter().write(s+"有权限访问此接口");
        return s;
    }
}
